#pragma

#include <pthread.h>
#include "Mutex.hpp"

namespace CondModule
{
    using namespace MutexModule;

    class Cond
    {
    public:
        Cond() 
        {
            ::pthread_cond_init(&_cond, nullptr);
        }

        ~Cond() 
        {
            ::pthread_cond_destroy(&_cond);
        }

        void Wait(Mutex &mutex) // 线程释放曾经持有的锁, 不能拷贝
        {
            ::pthread_cond_wait(&_cond, mutex.LockAddr());
        }

        void Signal()
        {
            ::pthread_cond_signal(&_cond);
        }

        void Broadcast()
        {
            ::pthread_cond_broadcast(&_cond);
        }

    private:
        pthread_cond_t _cond;
    };
}